package cn.fbs.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.ArrayList;

@Component
@Order(1)
public class CheckPath implements ApplicationRunner {
    @Value("${resource.locations}")
    private String resourceLocations;
    @Value("${image.upload.doestUrl}")
    private String imageUploadDoestUrl;
    @Value("${video.upload.doestUrl}")
    private String videoUploadDoestUrl;
    @Value("${data.upload.doestUrl}")
    private String dataUploadDoestUrl;
    @Value("${xml.upload.doestUrl}")
    private String xmlUploadDoestUrl;
    @Value("${logPath}")
    private String logPath;
    @Override
    public void run(ApplicationArguments args) {
        ArrayList<String> paths = new ArrayList<>();
        paths.add(resourceLocations);
        paths.add(imageUploadDoestUrl);
        paths.add(videoUploadDoestUrl);
        paths.add(dataUploadDoestUrl);
        paths.add(xmlUploadDoestUrl);
        paths.add(logPath);
        for (String path : paths) {
            File file = new File(path);
            if (!file.exists()) {
                file.mkdirs();
            }
        }

    }
}
